package com.mdb.open.trade.rabbit.provider;


import com.mdb.open.trade.config.RabbitConfig;
import com.mdb.open.trade.rabbit.model.RiskProviderMo;
import lombok.extern.log4j.Log4j2;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @description:
 * @author: you.yichao
 * @create: 2019-07-09 19:41
 **/
@Component
@Log4j2
public class RiskMerchantProvider implements RabbitTemplate.ReturnCallback {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    public void send(RiskProviderMo mo) {
        this.rabbitTemplate.setReturnCallback(this);
        this.rabbitTemplate.setConfirmCallback((correlationData, ack, cause) -> {
            if (!ack) {
                log.info("RiskMerchantProvider 消息发送失败" + cause + correlationData.toString());
            } else {
                log.info("RiskMerchantProvider 消息发送成功 ");
            }
        });
        this.rabbitTemplate.convertAndSend(RabbitConfig.TF_WEB_EXCHANGE, RabbitConfig.TRADE_FINANCE_MERCHANT_RISK, mo);
    }



    @Override
    public void returnedMessage(Message message, int replyCode, String replyText, String exchange, String routingKey) {
        log.info("sender return success" + message.toString()+"==="+replyCode+"==="+replyText+"==="+exchange);

    }
}
